package cjlu.ea.h.common;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/*
    用于String和时间格式转换
 */
public class TimeUtils {




    public static Boolean compareDate(String startTime,String endTime) {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        try {
            Date start = new Timestamp(dateFormat.parse(startTime).getTime());
            Date end = new Timestamp(dateFormat.parse(endTime).getTime());
            Date currentDate = new Date();
            Long dataLong = currentDate.getTime();
            Date current = new Timestamp(dataLong);

            System.out.println("start:"+start);
            System.out.println("end:"+end);
            System.out.println("current:"+current);

            if(start.after(end)){
                System.out.println("请按规范顺序输入");
            }

            if (current.equals(start)||current.equals(end)) {
                //恰好压点
                System.out.println("符合操作时间...");
                return true;
            } else if (current.compareTo(start)>0&&current.compareTo(end)<0) {
                System.out.println("在允许操作时间内...");
                return true;
            } else if (current.compareTo(end)>0) {
                System.out.println("操作时间已经结束，请等待下次...");
                return false;
            }else if(current.compareTo(start)<0){
                System.out.println("还没到操作时间请等待开放...");
                return false;
            }
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return false;
        }

        return false;

    }

}
